package com.bci.pwtz.admin.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;

import com.bci.pwtz.admin.service.ResourceTypeService;
import com.bci.pwtz.exception.PwtzDatabaseException;
import com.bci.pwtz.mysql.dao.ResourceTypeMapper;
import com.bci.pwtz.mysql.model.ResourceType;

public class ResourceTypeServiceImpl  implements ResourceTypeService{

	private ResourceTypeMapper resTypeMapper;
	 private static final Logger _logger = Logger.getLogger(ResourceTypeServiceImpl.class);
	

	public ResourceTypeMapper getResTypeMapper() {
		return resTypeMapper;
	}

	public void setResTypeMapper(ResourceTypeMapper resTypeMapper) {
		this.resTypeMapper = resTypeMapper;
	}

	public static Logger getLogger() {
		return _logger;
	}

	@Override
	public int deleteByPrimaryKey(int id) throws PwtzDatabaseException {
		if (_logger.isDebugEnabled())
        {
            _logger.debug("deleteByPrimaryKey=" + id);
        }
		int result=0;
		try {
			resTypeMapper.deleteByPrimaryKey(id);
			 result = 1;
		} catch (DataAccessException e) {
			   _logger.error(ExceptionUtils.getStackTrace(e));
	            throw new PwtzDatabaseException();
		}
		return result;
	}

	@Override
	public int deleteById(int id) throws PwtzDatabaseException {
		if (_logger.isDebugEnabled())
        {
            _logger.debug("deleteById=" + id);
        }
		int result = 0;
		try {
			resTypeMapper.deleteById(id);
			 result = 1;
		} catch (DataAccessException e) {
			   _logger.error(ExceptionUtils.getStackTrace(e));
	            throw new PwtzDatabaseException();
		}
		return result;
	}

	@Override
	public int insert(ResourceType resType) throws PwtzDatabaseException {
		if (_logger.isDebugEnabled())
        {
            _logger.debug("resourcetype : insert=" + resType.getTypeName());
        }
		int result = 0;
		try {
			resTypeMapper.insert(resType);
			result = 1;
		}catch (DataAccessException e) {
			   _logger.error(ExceptionUtils.getStackTrace(e));
	            throw new PwtzDatabaseException();
		}
		
		return result;
	}

	@Override
	public ResourceType load(int id) throws PwtzDatabaseException {
		ResourceType resType= null;
		if (_logger.isDebugEnabled())
        {
            _logger.debug("resourcetype : load=" + id);
        }
		try {
			resType = resTypeMapper.load(id);
		} catch (DataAccessException e) {
			   _logger.error(ExceptionUtils.getStackTrace(e));
	            throw new PwtzDatabaseException();
		}
		return resType;
	}

	@Override
	public int updateByPrimaryKey(ResourceType resType)
			throws PwtzDatabaseException {
		int result = 0;
		if (_logger.isDebugEnabled())
        {
            _logger.debug("resourcetype : updateByPrimaryKey=" + resType.getTypeName());
        }
		try {
			result = resTypeMapper.updateByPrimaryKey(resType);
		} catch (DataAccessException e) {
			   _logger.error(ExceptionUtils.getStackTrace(e));
	            throw new PwtzDatabaseException();
		}
		return result;
	}

	@Override
	public List<ResourceType> selectRestypeList() throws PwtzDatabaseException {
		List<ResourceType> list = new ArrayList<ResourceType>();
		if (_logger.isDebugEnabled())
        {
            _logger.debug("resourcetype : selectRestypeList:条数---->" + list.size());
        }
		try {
			list = resTypeMapper.selectRestypeList();
		} catch (DataAccessException e) {
			   _logger.error(ExceptionUtils.getStackTrace(e));
	            throw new PwtzDatabaseException();
		}
		return list;
	}

	@Override
	public List<ResourceType> selectjjfa() throws PwtzDatabaseException {

		List<ResourceType> list = new ArrayList<ResourceType>();
		if (_logger.isDebugEnabled())
        {
            _logger.debug("resourcetype : selectjjfa:条数---->" + list.size());
        }
		try {
			list = resTypeMapper.selectjjfa();
		} catch (DataAccessException e) {
			   _logger.error(ExceptionUtils.getStackTrace(e));
	            throw new PwtzDatabaseException();
		}
		return list;
	
	}

	

}
